<?php

namespace Havoo\Core;

use PDO;

class PdoDriver
{

    protected static $_instance = null;

    private function __construct()
    {
    }

    private function __clone()
    {
    }

    public static function getInstance($host, $user, $passwd, $dbname, $charset)
    {
        if (self::$_instance === null) {
            try {
                $dsn = sprintf("mysql:host=%s;dbname=%s;charset=%s;unix_socket=/var/lib/mysql/mysql.sock", $host, $dbname, $charset);
                self::$_instance = new PDO($dsn, $user, $passwd, 
                    array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC));
            } catch (PDOException $e) {
                exit('database connect error :' . $e->getMessage());
            }
        }
        return self::$_instance;
    }

}
